#include "JPVec3.h"

#include <math.h>

const JPVec3 JPVec3::vecX = JPVec3(1.0f,0.0f,0.0f);
const JPVec3 JPVec3::vecY = JPVec3(0.0f,1.0f,0.0f);
const JPVec3 JPVec3::vecZ = JPVec3(0.0f,0.0f,1.0f);

float JPVec3::dot(const JPVec3 &v) const
{
	return (x*v.x)+(y*v.y)+(z*v.z);
}

JPVec3 JPVec3::cross(const JPVec3 &v) const
{
	return JPVec3(	(y * v.z)-(z * v.y),	// |   i   j    k   |
					(z * v.x)-(x * v.z),	// | v1.x v1.y v1.z |
					(x * v.y)-(y * v.x)	);	// | v2.x v2.y v2.z |
}

float JPVec3::magnitude() const
{
	return sqrtf(x*x+y*y+z*z);
}

float JPVec3::sqrMagnitude() const
{
	return x*x+y*y+z*z;
}

void JPVec3::normalise()
{
	(*this)/=magnitude();
}

JPVec3 JPVec3::getNormalised() const
{
	return (*this)/magnitude();
}